package dobest.ray.com.jiongjiong.activity.action;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import dobest.ray.com.jiongjiong.R;
import dobest.ray.com.jiongjiong.activity.AmapDemoActivity;
import dobest.ray.com.jiongjiong.activity.BaseFragment;
import dobest.ray.com.jiongjiong.activity.action.EyeExercises.EyeExercisesActivity;
import dobest.ray.com.jiongjiong.activity.action.selftest.VisionSelfTestChooseActivity;
import dobest.ray.com.jiongjiong.activity.action.service.ServiceActivity;
import dobest.ray.com.jiongjiong.activity.mumingleshi.BindDeviceActivity;
import dobest.ray.com.jiongjiong.activity.mumingleshi.MumingleshiActivity;
import dobest.ray.com.jiongjiong.bean.BindDeviceBean;
import dobest.ray.com.jiongjiong.utils.ACacheHelper;
import dobest.ray.com.jiongjiong.views.CoustomNoticeDialog;
import dobest.ray.com.jiongjiong.views.NavigationBar;

/**
 * Created by Ray on 2016/3/16.
 * https://github.com/ray0807
 * 行动起来
 */
public class GoIntoActionFragment extends BaseFragment implements View.OnClickListener {
    private NavigationBar navi;
    /**
     * activity 实例
     */
    private Activity mActivity;

    private RelativeLayout rl_eye_exercise;
    private LinearLayout ll_comment_1;
    private LinearLayout ll_vision_self_test;
    private LinearLayout ll_take_photo;
    private RelativeLayout rl_public_service;
    private RelativeLayout rl_private_service;


    private BindDeviceBean bean;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mActivity = getActivity();
        return inflater.inflate(R.layout.fragment_go_into_action, container, false);
    }

    @Override
    protected void findViews(View view) {
        navi = (NavigationBar) view.findViewById(R.id.navi);
        navi.setTitle("行动起来");
        ll_comment_1 = (LinearLayout) view.findViewById(R.id.ll_comment_1);
        ll_vision_self_test = (LinearLayout) view.findViewById(R.id.ll_vision_self_test);
        ll_take_photo = (LinearLayout) view.findViewById(R.id.ll_take_photo);

        rl_eye_exercise = (RelativeLayout) view.findViewById(R.id.rl_eye_exercise);

        rl_public_service = (RelativeLayout) view.findViewById(R.id.rl_public_service);
        rl_private_service = (RelativeLayout) view.findViewById(R.id.rl_private_service);
    }

    @Override
    protected void init() {

    }

    @Override
    protected void addListeners() {
        rl_eye_exercise.setOnClickListener(this);
        ll_comment_1.setOnClickListener(this);
        ll_vision_self_test.setOnClickListener(this);
        rl_private_service.setOnClickListener(this);
        rl_public_service.setOnClickListener(this);
        ll_take_photo.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent it = null;
        switch (v.getId()) {
            case R.id.rl_eye_exercise:
                it = new Intent(mActivity, EyeExercisesActivity.class);
                break;
            case R.id.ll_comment_1:
                bean = ACacheHelper.getInstance().getBindDevices(getActivity());
//                it = new Intent(mActivity, MuMingLeShiActivityWelcomeActivity.class);
                if (bean != null) {
                    it = new Intent(mActivity, MumingleshiActivity.class);
                } else {
                   final CoustomNoticeDialog dialog = new CoustomNoticeDialog(mActivity);
                    dialog.setTitle("您暂未绑定");
                    dialog.setContent("是否进入绑定界面进行绑定？");
                    dialog.setConfirmListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent it1 = new Intent(mActivity, BindDeviceActivity.class);
                            mActivity.startActivity(it1);
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
                break;
            case R.id.ll_vision_self_test:
                it = new Intent(mActivity, VisionSelfTestChooseActivity.class);
                break;
            case R.id.rl_public_service:
                it = new Intent(mActivity, ServiceActivity.class);
                break;
            case R.id.rl_private_service:
                it = new Intent(mActivity, ServiceActivity.class);
                break;
            case R.id.ll_take_photo:
                it = new Intent(mActivity, AmapDemoActivity.class);
                break;
        }
        if (it != null) {
            mActivity.startActivity(it);
        }
    }
}
